<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定位练习</title>
    <style>
        .box {
            width: 300px;
            height: 250px;
            position: absolute;
            /*垂直居中*/
            left: 50%;
            margin-left: -150px;
            /*水平居中*/
            top: 50%;
            margin-top: -125px;
           /* 绝对定位的盒子设置margin无效
            margin: 0 auto;*/
            background-color: #a0d911;
        }

    </style>
</head>
<body>

<div class="box"></div>

</body>
</html>